package com.deltabravomedia.theoldtoad;

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class DrinksBeersBottles extends ListActivity {
	private static final int ACTIVITY_BARLEY_WINE=0;
	private static final int ACTIVITY_BELGIAN_PALE_ALE=1;
	private static final int ACTIVITY_BELGIAN_STRONG_DARK_ALE=2;
	private static final int ACTIVITY_BELGIAN_STRONG_PALE_ALE=3;
	private static final int ACTIVITY_BERLINER_WEISSE=4;
	private static final int ACTIVITY_BITTER=5;
	private static final int ACTIVITY_BITTER_PALE_ALE=6;
	private static final int ACTIVITY_BITTER_PALE_ALE_STRONG_BITTER=7;
	private static final int ACTIVITY_BROWN_ALE=8;
	private static final int ACTIVITY_DOPPELBOCK=9;
	private static final int ACTIVITY_DUNKEL_WEISSE=10;
	private static final int ACTIVITY_EISBOCK=11;
	private static final int ACTIVITY_FRUIT_BEER=12;
	private static final int ACTIVITY_HARD_CIDER=13;
	private static final int ACTIVITY_HEFE_WEIZEN=14;
	private static final int ACTIVITY_IMPERIAL_STOUT=15;
	private static final int ACTIVITY_IPA_AMERICAN=16;
	private static final int ACTIVITY_IPA_ENGLISH=17;
	private static final int ACTIVITY_LAGER_AMBER=18;
	private static final int ACTIVITY_LAGER_BLONDE=19;
	private static final int ACTIVITY_LAMBIC=20;
	private static final int ACTIVITY_OTHER=21;
	private static final int ACTIVITY_PORTER=22;
	private static final int ACTIVITY_SAISON=23;
	private static final int ACTIVITY_SCOTCH_ALE=24;
	private static final int ACTIVITY_STRONG_BITTER=25;
	private static final int ACTIVITY_TRAPPIST=26;
	private static final int ACTIVITY_WEIZEN_BOCK=27;
	private static final int ACTIVITY_WIT_BIER=28;
	
	private static final String TAG = "";

	private ProgressDialog m_ProgressDialog = null; 
    private ArrayList<Item> m_items = null;
    private ItemAdapter m_adapter;
    private Runnable viewItems;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listviewwithbackgroundimage);
        this.setTitle("The Old Toad : Drinks : Beers : Bottles");
        m_items = new ArrayList<Item>();
        this.m_adapter = new ItemAdapter(this, R.layout.row, m_items);
                setListAdapter(this.m_adapter);
        
        viewItems = new Runnable(){
            @Override
            public void run() {
                getItems();
            }
        };
        
        Thread thread =  new Thread(null, viewItems, "MagentoBackground");
        thread.start();
        m_ProgressDialog = ProgressDialog.show(DrinksBeersBottles.this,    
              "Please wait...", "Retrieving data ...", true);
    }
    
	@Override
    protected void onListItemClick (ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        
        Log.i(TAG, m_items.get(position).getItemName());
        
        String item = m_items.get(position).getClassName();
        
        if (item.equals("BarleyWine")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Barley Wine");
            i.putExtra("type", "BarleyWine");
            startActivityForResult(i, ACTIVITY_BARLEY_WINE);
        } else if (item.equals("BelgianPaleAle")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Belgian Pale Ale");
            i.putExtra("type", "BelgianPaleAle");            
            startActivityForResult(i, ACTIVITY_BELGIAN_PALE_ALE);
        } else if (item.equals("BelgianStrongDarkAle")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Belgian Stong Dark Ale");
            i.putExtra("type", "BelgianStrongDarkAle");            
            startActivityForResult(i, ACTIVITY_BELGIAN_STRONG_DARK_ALE);
        } else if (item.equals("BelgianStrongPaleAle")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Belgian Strong Pale Ale");
            i.putExtra("type", "BelgianStrongPaleAle");            
            startActivityForResult(i, ACTIVITY_BELGIAN_STRONG_PALE_ALE);
        } else if (item.equals("BerlinerWeisse")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Berliner Weisse");
            i.putExtra("type", "BerlinerWeisse");            
            startActivityForResult(i, ACTIVITY_BERLINER_WEISSE);
        } else if (item.equals("Bitter")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Bitter");
            i.putExtra("type", "Bitter");            
            startActivityForResult(i, ACTIVITY_BITTER);
        } else if (item.equals("BitterPaleAle")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Bitter/Pale Ale");
            i.putExtra("type", "BitterPaleAle");            
            startActivityForResult(i, ACTIVITY_BITTER_PALE_ALE);
        } else if (item.equals("BitterPaleAleStrongBitter")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Bitter/Pale Ale Strong Bitter");
            i.putExtra("type", "BitterPaleAleStrongBitter");            
            startActivityForResult(i, ACTIVITY_BITTER_PALE_ALE_STRONG_BITTER);
        } else if (item.equals("BrownAle")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Brown Ale");
            i.putExtra("type", "BrownAle");            
            startActivityForResult(i, ACTIVITY_BROWN_ALE);
        } else if (item.equals("Doppelbock")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Doppelbock");
            i.putExtra("type", "Doppelbock");            
            startActivityForResult(i, ACTIVITY_DOPPELBOCK);
        } else if (item.equals("DunkelWeisse")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Dunkel-Weisse");
            i.putExtra("type", "DunkelWeisse");            
            startActivityForResult(i, ACTIVITY_DUNKEL_WEISSE);
        } else if (item.equals("Eisbock")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Eisbock");
            i.putExtra("type", "Eisbock");            
            startActivityForResult(i, ACTIVITY_EISBOCK);
        } else if (item.equals("FruitBeer")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Fruit Beer");
            i.putExtra("type", "FruitBeer");            
            startActivityForResult(i, ACTIVITY_FRUIT_BEER);
        } else if (item.equals("HardCider")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Hard Cider");
            i.putExtra("type", "HardCider");            
            startActivityForResult(i, ACTIVITY_HARD_CIDER);
        } else if (item.equals("HefeWeizen")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Hefe Weizen");
            i.putExtra("type", "HefeWeizen");            
            startActivityForResult(i, ACTIVITY_HEFE_WEIZEN);
        } else if (item.equals("ImperialStout")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : ImperialStout");
            i.putExtra("type", "ImperialStout");            
            startActivityForResult(i, ACTIVITY_IMPERIAL_STOUT);
        } else if (item.equals("IPAAmerican")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : I.P.A. American");
            i.putExtra("type", "IPAAmerican");            
            startActivityForResult(i, ACTIVITY_IPA_AMERICAN);
        } else if (item.equals("IPAEnglish")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : I.P.A. English");
            i.putExtra("type", "IPAEnglish");            
            startActivityForResult(i, ACTIVITY_IPA_ENGLISH);
        } else if (item.equals("LagerAmber")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Lager Amber");
            i.putExtra("type", "LagerAmber");            
            startActivityForResult(i, ACTIVITY_LAGER_AMBER);
        } else if (item.equals("LagerBlonde")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Lager Blonde");
            i.putExtra("type", "LagerBlonde");            
            startActivityForResult(i, ACTIVITY_LAGER_BLONDE);
        } else if (item.equals("Lambic")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Lambic");
            i.putExtra("type", "Lambic");            
            startActivityForResult(i, ACTIVITY_LAMBIC);
        } else if (item.equals("Other")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Other");
            i.putExtra("type", "Other");            
            startActivityForResult(i, ACTIVITY_OTHER);
        } else if (item.equals("Porter")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Porter");
            i.putExtra("type", "Porter");            
            startActivityForResult(i, ACTIVITY_PORTER);
        } else if (item.equals("Saison")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Saison");
            i.putExtra("type", "Saison");            
            startActivityForResult(i, ACTIVITY_SAISON);
        } else if (item.equals("ScotchAle")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Scotch Ale");
            i.putExtra("type", "ScotchAle");            
            startActivityForResult(i, ACTIVITY_SCOTCH_ALE);
        } else if (item.equals("StrongBitter")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Strong Bitter");
            i.putExtra("type", "StrongBitter");            
            startActivityForResult(i, ACTIVITY_STRONG_BITTER);
        } else if (item.equals("Trappist")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Trappist");
            i.putExtra("type", "Trappist");            
            startActivityForResult(i, ACTIVITY_TRAPPIST);
        } else if (item.equals("WeizenBock")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Weizen Bock");
            i.putExtra("type", "WeizenBock");            
            startActivityForResult(i, ACTIVITY_WEIZEN_BOCK);
        } else if (item.equals("WitBier")) {
            Intent i = new Intent(this, ItemsList.class);
            i.putExtra("title", "Drinks : Beer : Bottles : Wit Bier");
            i.putExtra("type", "WitBier");            
            startActivityForResult(i, ACTIVITY_WIT_BIER);
        }
	}   
    
    private Runnable returnRes = new Runnable() {
        @Override
        public void run() {
            if(m_items != null && m_items.size() > 0){
                m_adapter.notifyDataSetChanged();
                for(int i=0;i<m_items.size();i++)
                m_adapter.add(m_items.get(i));
            }
            m_ProgressDialog.dismiss();
            m_adapter.notifyDataSetChanged();
        }
    };
    
    private class ItemAdapter extends ArrayAdapter<Item> {

        private ArrayList<Item> items;

        public ItemAdapter(Context context, int textViewResourceId, ArrayList<Item> items) {
	        super(context, textViewResourceId, items);
	        this.items = items;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
			View view = convertView;
			if (view == null) {
			    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			    view = vi.inflate(R.layout.row, null);
			}
			Item item = items.get(position);
			if (item != null) {
		        TextView topText = (TextView) view.findViewById(R.id.toptext);
		        if (topText != null) {
		              topText.setText( item.getItemName());                            
		        }
			}
			return view;
        }
    }
    
    private void getItems(){
		m_items = new ArrayList<Item>();
		
		Item item0 = new Item();
		item0.setItemName("Barley Wine");
		item0.setClassName("BarleyWine");
		m_items.add(item0);
		
		Item item1 = new Item();
		item1.setItemName("Belgian Pale Ale");
		item1.setClassName("BelgianPaleAle");
		m_items.add(item1);
		
		Item item2 = new Item();
		item2.setItemName("Belgian Strong Dark Ale");
		item2.setClassName("BelgianStrongDarkAle");
		m_items.add(item2);
		
		Item item3 = new Item();
		item3.setItemName("Belgian Strong Pale Ale");
		item3.setClassName("BelgianStrongPaleAle");
		m_items.add(item3);
		
		Item item4 = new Item();
		item4.setItemName("Berliner Weisse");
		item4.setClassName("BerlinerWeisse");
		m_items.add(item4);
		
		Item item5 = new Item();
		item5.setItemName("Bitter");
		item5.setClassName("Bitter");
		m_items.add(item5);
		
		Item item6 = new Item();
		item6.setItemName("Bitter/Pale Ale");
		item6.setClassName("BitterPaleAle");
		m_items.add(item6);
		
		Item item7 = new Item();
		item7.setItemName("Bitter/Pale Ale Strong Bitter");
		item7.setClassName("BitterPaleAleStrongBitter");
		m_items.add(item7);
		
		Item item8 = new Item();
		item8.setItemName("Brown Ale");
		item8.setClassName("BrownAle");
		m_items.add(item8);
		
		Item item9 = new Item();
		item9.setItemName("Doppelbock");
		item9.setClassName("Doppelbock");
		m_items.add(item9);
		
		Item item10 = new Item();
		item10.setItemName("Dunkel Weisse");
		item10.setClassName("DunkelWeisse");
		m_items.add(item10);
		
		Item item11 = new Item();
		item11.setItemName("Eisbock");
		item11.setClassName("Eisbock");
		m_items.add(item11);
		
		Item item12 = new Item();
		item12.setItemName("Fruit Beer");
		item12.setClassName("FruitBeer");
		m_items.add(item12);		
		
		Item item13 = new Item();
		item13.setItemName("Hard Cider");
		item13.setClassName("HardCider");
		m_items.add(item13);
		
		Item item14 = new Item();
		item14.setItemName("Hefe Weizen");
		item14.setClassName("HefeWeizen");
		m_items.add(item14);		
		
		Item item15 = new Item();
		item15.setItemName("Imperial Stout");
		item15.setClassName("ImperialStout");
		m_items.add(item15);
		
		Item item16 = new Item();
		item16.setItemName("I.P.A. American");
		item16.setClassName("IPAAmerican");
		m_items.add(item16);
		
		Item item17 = new Item();
		item17.setItemName("I.P.A. English");
		item17.setClassName("IPAEnglish");
		m_items.add(item17);
		
		Item item18 = new Item();
		item18.setItemName("Lager Amber");
		item18.setClassName("LagerAmber");
		m_items.add(item18);
		
		Item item19 = new Item();
		item19.setItemName("Lager Blonde");
		item19.setClassName("LagerBlonde");
		m_items.add(item19);
		
		Item item20 = new Item();
		item20.setItemName("Lambic");
		item20.setClassName("Lambic");
		m_items.add(item20);
		
		Item item21 = new Item();
		item21.setItemName("Other");
		item21.setClassName("Other");
		m_items.add(item21);
		
		Item item22 = new Item();
		item22.setItemName("Porter");
		item22.setClassName("Porter");
		m_items.add(item22);
		
		Item item23 = new Item();
		item23.setItemName("Saison");
		item23.setClassName("Saison");
		m_items.add(item23);
		
		Item item24 = new Item();
		item24.setItemName("Scotch Ale");
		item24.setClassName("ScotchAle");
		m_items.add(item24);
		
		Item item25 = new Item();
		item25.setItemName("Strong Bitter");
		item25.setClassName("StrongBitter");
		m_items.add(item25);
		
		Item item26 = new Item();
		item26.setItemName("Trappist");
		item26.setClassName("Trappist");
		m_items.add(item26);
		
		Item item27 = new Item();
		item27.setItemName("Weizen Bock");
		item27.setClassName("WeizenBock");
		m_items.add(item27);
		
		Item item28 = new Item();
		item28.setItemName("Wit Bier");
		item28.setClassName("WitBier");
		m_items.add(item28);
		Log.i("ARRAY", ""+ m_items.size());
		  
		runOnUiThread(returnRes);
    }
}